package life.huangzhi.community.community.mapper;

import java.sql.Statement;

import life.huangzhi.community.community.dto.QuestionDTO;
import life.huangzhi.community.community.model.Question;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface QuestionMapper {
    /**
     * 注解的方式插入提问数据
     */
    @Insert("insert into question (title,description,gmt_create,gmt_modified,creator,tag) " +
            "values (#{title},#{description},#{gmtCreate},#{gmtModified},#{creator},#{tag})")
    void create (Question question);

    /**
     * 携带分页信息的全部提问查询
     */
    @Select("select * from question limit #{offset},#{pageSize}")
    List< Question > queryQuestion (@Param(value="offset") Integer offset, @Param(value = "pageSize") Integer pageSize);
    /**
     * 携带分页信息的个人提问查询
     */
    @Select("select * from question where creator = #{userId} limit #{offset},#{pageSize}")
    List<Question> queryQuestionByUserId(@Param(value = "userId") Integer userId, @Param(value="offset") Integer offset, @Param(value = "pageSize") Integer pageSize);
    /**
     * 携带分页信息的全部提问数量查询
     */
    @Select("select count(1) from question")
    Integer questionCount();
    /**
     * 携带分页信息的个人提问数量查询
     */
    @Select("select count(1) from question where creator = #{userId}")
    Integer questionCountByUserId(@Param(value = "userId") Integer userId);

    @Select("select * from question where id =#{id}")
    Question getById(@Param("id") Integer id);

    @Update("update question set title = #{title} ,description = #{description},tag = #{tag} where id = #{id}")
    void update(Question question);
}
